Address calling class [Java]
Posted
by Samuel
on Stack Overflow
See other posts from Stack Overflow
or by Samuel
Published on 2010-05-20T10:54:03Z
Indexed on
2010/05/20
11:00 UTC
Read the original article
Hit count: 443
Hello!
[I am rather new to Java and Object Oriented programming]
I have an abstract class Moveable with the method abstract void move()
which is extended by the class Bullet and the abstract class Character, and Character is extended by the class Survivor and the class Zombie. In Survivor and Bullet the move()
method doesnt require any parameters while in the class Zombie the move()
method depends on the actual position of the survivor. The survivor and multiple zombies are created in the class Gui.
I wanted to access the survivor in Zombie - what's the best way of doing this? In Gui i wrote a method getSurvivor()
but i don't see how to access this method in Zombie?
I am aware that as a workaround i could just pass a [Survivor survivor] as parameter in move()
and ignore it in Bullet and Survivor, but that feels so ... bad practice.
Thank you for your time!
- Samuel
[I am not sure what tags to set here, please correct me if i'm wrong]
© Stack Overflow or respective owner